namespace SuperSocketProxy;

internal sealed class PacketFactoryPool
{
    private readonly Dictionary<SocketPipeFilterType, IPacketFactory> _packetFactorys = new();
    
    public void RegisterPacketType<TPacket>(SocketPipeFilterType filterType)
        where TPacket : SocketProxyPacket, new()
    {
        _packetFactorys.TryAdd(filterType, new DefaultPacketFactory<TPacket>());
    }

    public SocketProxyPacket Create(SocketPipeFilterType filterType)
    {
        if (_packetFactorys.TryGetValue(filterType, out var factory))
            return factory.Create();
        
        throw new Exception($"暂未注册此过滤器{filterType}");
    }
}